<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Operate Documents</title>
    <script language="JavaScript">
	</script>
	<style type="text/css">
	<!--
	body {
		margin-left: 0px;
		margin-top: 0px;
		margin-right: 0px;
		margin-bottom: 0px;
		background-color: #EEF2FB;
	}
	.titlebt_custom {
		font-size: 12px;
		line-height: 26px;
		font-weight: bold;
		color: #000000;
		background-image: url(../images/content-bg.gif);
		background-repeat: no-repeat;
		display: block;
		text-indent: 15px;
		padding-top: 5px;
	}
	-->
	</style>
	<link href="../images/skin.css" rel="stylesheet" type="text/css" />
	<script type="text/javascript">
		var current_page = 0;
		var records = undefined;
		function fileJson(record){
			var fields = record.split(",");
			if(fields.length == 2){
				var _path = fields[0];
				var file = {
					path:fields[0],
					lastModified:fields[1],
					filename:fields[0].substring(_path.lastIndexOf("\\") + 1, _path.length)
				};
				return file;
			}
		}
		function init(){
		   var ds = document.getElementById("dataset");
		   var _records = ds.getElementsByTagName("span");
			if(null != _records && _records.length > 0){
				current_page = 1;
				records = _records;
				var record_ = fileJson(records[0].firstChild.nodeValue);
				if(typeof(window.iframe_show.show_applet_absoute)=="function"){
					renderLabel(record_.filename, record_.lastModified);
					window.iframe_show.show_applet_absoute(record_.path);
				}
			}
		}
		function first(){
			current_page = 1;
			window.iframe_show.location.href="frame_temp.jsp";
		}
		function previous(){
			if(current_page == 1){
				alert("No pervious Page!");
			}else{
				current_page = current_page  - 1;
				window.iframe_show.location.href="frame_temp.jsp";
			}
		}
		function next(flag){
			if(current_page == records.length){
				alert("No next Page!");
			}else{
				current_page = current_page + 1;
				window.iframe_show.location.href="frame_temp.jsp";
			}
		}
		function bottom(){
			current_page = records.length;
			window.iframe_show.location.href="frame_temp.jsp";
		}
		function openpdf(){
			if(typeof(window.iframe_show.show_applet_absoute)=="function"){
				var record_ = fileJson(records[current_page - 1].firstChild.nodeValue);
				renderLabel(record_.filename, record_.lastModified);
				window.iframe_show.show_applet_absoute(record_.path);
			}
		}
		function renderLabel(filename, lastModified){
			var label_ = document.getElementById("filename");
			var childs = label_.childNodes;
			for(var i = childs.length - 1; i >= 0; i--) {  
			    label_.removeChild(childs[i]);   
			}
			label_.appendChild(document.createTextNode(filename));			
			var input_ = document.getElementById("d_filename");
			input_.value = filename;			
			var receiveTimes_ = document.getElementById("receiveTimes");
			receiveTimes_.value = lastModified;			
			rebuild_f();
		}
		function rebuild_f(){
			var filenames = "";
			var flag = false;
			for(var i = 0; i < records.length; i++){
				var record_ = fileJson(records[i].firstChild.nodeValue);
				if((i + 1) != current_page){
					if(!flag){
						filenames = filenames + record_.path;
						flag = true;
					}else{
						filenames = filenames + "#spliter#" +  record_.path;
					}
				}
			}
			var filenames_ = document.getElementById("filenames");
			filenames_.value = filenames;
		}
	</script>
</head>
<body onload=init();>    
<div id="dataset" style="display: none">
	<s:iterator value="timeArray" status="stts">
		<span id="record<s:property value="#stts.index"/>"><s:property value="timeArray[#stts.index]"/></span>
	</s:iterator>
</div>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
		<tr>
			<td colspan="3">
			 <table width="100%" border="0" cellpadding="0" cellspacing="0">
			 	<tr>
			 		<td width="17" valign="top" background="../images/mail_leftbg.gif"><img src="../images/left-top-right.gif" width="17" height="29" /></td>
				    <td valign="top" background="../images/content-bg.gif"><table width="100%" height="31" border="0" cellpadding="0" cellspacing="0" class="left_topbg" id="table2">
				      <tr>
				        <td height="31"><div id="title" class="titlebt_custom">
				          Operate Documents
				        </div></td>
				      </tr>
				    </table></td>
				    <td width="16" valign="top" background="../images/mail_rightbg.gif"><img src="../images/nav-right-bg.gif" width="16" height="29" /></td>
			 	</tr>
			 </table>
			</td>    
		</tr>
		<tr bgcolor="#F7F8F9">
			<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
			<td align="left">FileName:<label id="filename"/></td>
			<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
		</tr>
		<tr bgcolor="#F7F8F9">
			<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
			<td align="left"><a href="javascript:first();">First</a>&nbsp;<a href="javascript:previous();">Previous</a>&nbsp;<a href="javascript:next();">Next</a>&nbsp;<a href="javascript:bottom();">Bottom</a></td>
			<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
		</tr>
		<tr bgcolor="#F7F8F9">
			<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
			<td align="left"><iframe border="0" id="iframe_show" src="frame_temp.jsp" width="100%" height="958"></iframe></td>
			<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
		</tr>
		<tr bgcolor="#F7F8F9">
			<td width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
			<td align="left"><a href="javascript:first();">First</a>&nbsp;<a href="javascript:previous();">Previous</a>&nbsp;<a href="javascript:next();">Next</a>&nbsp;<a href="javascript:bottom();">Bottom</a></td>
			<td width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
		</tr>
		<tr bgcolor="#F7F8F9">
			<td colspan="1" width="17" background="../images/mail_leftbg.gif"><img src="../images/mail_leftbg.gif" width="17" height="17" /></td>
			<td colspan="1" width="100%" height="100%">
			    <s:form action="saveAllDocuemt" name="form1">
			        <s:hidden name="document.filename" id="d_filename" label="File Name" />
			        <s:hidden name="receiveTimes" id="receiveTimes" label="Receive Times" />
			        <s:hidden name="filenames" id="filenames" label="filenames" />
			         <s:select name="document.hospital.id" label="User" list="hospitals" listKey="id" listValue="name"></s:select>  
			        <s:select name="document.detailUserByUserId.id" label="User" list="users" listKey="user.detailUser.id" listValue="user.username"></s:select>  			       
			        <s:textarea name="document.introduction" label="Introduction" />
			        <s:hidden name="document.id"/>
			        <s:submit />
			    </s:form>
			</td>
			<td colspan="1" width="16" background="../images/mail_rightbg.gif"><img src="../images/mail_rightbg.gif" width="16" height="17" /></td>
		</tr>
		<tr>
			<td colspan="3">
				<table width="100%" border="0" cellpadding="0" cellspacing="0">
				 	<tr>
				 		<td width="17" valign="top" background="../images/mail_leftbg.gif"><img src="../images/buttom_left2.gif" width="17" height="17" /></td>
					    <td valign="top" background="../images/buttom_bgs.gif"><img src="../images/buttom_bgs.gif" width="17" height="17"></td>
					    <td width="16" valign="top" background="../images/mail_rightbg.gif"><img src="../images/buttom_right2.gif" width="16" height="17" /></td>
				 	</tr>
				 </table>	
			 </td>	
		</tr>
</table>

</body>
</html>